# -*- coding: utf-8 -*-
import requests
from lxml import etree
from tools.mysqlconn import NBAdb
from mysql_text import sql_insert_text
from tools.auxiliary_tool import normalization


class Base:

    def __init__(self):
        """
        初始化一些东西。
        """
        # 解析HTML
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'
        }
        res = requests.get('http://www.stat-nba.com/teamList.php', headers=self.headers)
        res.encoding = 'utf-8'
        html = etree.HTML(res.text)

        # 创建一个存放所有球队链接的列表
        self.url_list = []
        # 创建一个存放球队名字的字典
        self.name_dic = {}
        # 现役球队
        content_url_one = html.xpath('//div[@class="stat_box"]//td//a/@href')
        content_name_one = html.xpath('//div[@class="stat_box"]//td//a//text()')
        # 历史球队
        content_url_two = html.xpath('//div[@class="teamList"]//a/@href')
        content_url_two.remove('./team/NONE.html')  # 删除一个空的链接
        content_name_two = normalization(html.xpath('//div[@class="teamList"]//a//text()'))
        # 使用zip()方法并行迭代
        for x, y in zip(content_url_one, content_name_one):
            self.url_list.append('http://www.stat-nba.com'+x[1:])
            self.name_dic['http://www.stat-nba.com'+x[1:]] = y
        for x, y in zip(content_url_two, content_name_two):
            self.url_list.append('http://www.stat-nba.com' + x[1:])
            self.name_dic['http://www.stat-nba.com' + x[1:]] = y

    def get_team_brief_introduction(self):
        """
        获取球队简介数据（包含1个表）
        :return:
        """
        one = NBAdb()

        for url in self.url_list:
            res = requests.get(url, headers=self.headers)
            res.encoding = 'utf-8'
            html = etree.HTML(res.text)

            if html.xpath('//div[@class="text"]'):
                name = self.name_dic[url]
                try:
                    English_name = html.xpath('//div[@class="text"]//div[contains(text(),"英文名")]/../div[@class="value"]//text()')
                except:
                    English_name = ''

                try:
                    champion_season = html.xpath('//div[@class="text"]//div[contains(text(),"夺冠赛季")]/../div[@class="value"]//text()')
                except:
                    champion_season = ''

                try:
                    retired_number = html.xpath('//div[@class="text"]//div[contains(text(),"退役球衣")]/../div[@class="value"]//text()')
                except:
                    retired_number = ''

                list_bi = [name, normalization(English_name)[0], "".join(normalization(champion_season)),
                           "".join(normalization(retired_number))]
                one.insert_table(sql_insert_text.insert_team_brief_introduction, list_bi)
            else:
                pass

        # 释放资源
        del one

    def get_team_superstar_data(self):
        """
        获取队史巨星数据记录数据（包含48个表）
        :return:
        """
        one = NBAdb()

        for url in self.url_list:
            # 解析HTML文档
            res = requests.get(url, headers=self.headers)
            res.encoding = 'utf-8'
            html = etree.HTML(res.text)

            # 通过URL在字典中获取球队名
            name = self.name_dic[url]

            # (1)常规赛得分榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0pts0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0pts0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsst = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsst.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_score_total, list_rsst)

            # (2)常规赛得分榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0pts1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0pts1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rssa = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rssa.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_score_average, list_rssa)

            # (3)常规赛篮板榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0trb0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0trb0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsbt = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsbt.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_backboard_total, list_rsbt)

            # (4)常规赛篮板榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0trb1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0trb1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsba = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsba.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_backboard_average, list_rsba)

            # (5)常规赛助攻榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0ast0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0ast0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsat = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsat.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_assists_total, list_rsat)

            # (6)常规赛助攻榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0ast1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0ast1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsaa = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsaa.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_assists_average, list_rsaa)

            # (7)常规赛抢断榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0stl0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0stl0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsst = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsst.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_steal_total, list_rsst)

            # (8)常规赛抢断榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0stl1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0stl1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rssa = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rssa.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_steal_average, list_rssa)

            # (9)常规赛盖帽榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0blk0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0blk0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsct = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsct.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_cap_total, list_rsct)

            # (10)常规赛盖帽榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0blk1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0blk1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsca = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsca.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_cap_average, list_rsca)

            # (11)常规赛失误榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0tov0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0tov0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsmt = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsmt.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_mistake_total, list_rsmt)

            # (12)常规赛失误榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0tov1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0tov1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsma = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsma.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_mistake_average, list_rsma)

            # (13)常规赛犯规榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0pf0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0pf0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsft = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsft.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_foul_total, list_rsft)

            # (14)常规赛犯规榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0pf1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0pf1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsfa = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsfa.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_foul_average, list_rsfa)

            # (15)常规赛命中榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0fg0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0fg0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsht = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsht.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_hit_total, list_rsht)

            # (16)常规赛命中榜命中率表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0fg1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0fg1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rshr = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rshr.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_hit_rate, list_rshr)

            # (17)常规赛真实命中榜表
            if html.xpath('//div[@id="leaderList0"]//div[@id="ts0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="ts0"]/div')
                for i in content_one:
                    list_rsth = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsth.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_ture_hit, list_rsth)

            # (18)常规赛三分榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0threep0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0threep0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rstt = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rstt.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_tp_total, list_rstt)

            # (19)常规赛三分榜命中率表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0threep1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0threep1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsthr = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsthr.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_tp_hit_rate, list_rsthr)

            # (20)常规赛罚球榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0ft0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0ft0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rspt = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rspt.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_penalty_total, list_rspt)

            # (21)常规赛罚球榜命中率表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0ft1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0ft1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsphr = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsphr.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_penalty_hit_rate, list_rsphr)

            # (22)常规赛打铁榜总计表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0kobe0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0kobe0"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsut = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsut.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_undefined_total, list_rsut)

            # (23)常规赛打铁榜场均表
            if html.xpath('//div[@id="leaderList0"]//div[@id="0kobe1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="0kobe1"]/div[@class="content"]/div')
                for i in content_one:
                    list_rsua = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsua.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_undefined_average, list_rsua)

            # (24)获取常规赛出场次数榜表
            if html.xpath('//div[@id="leaderList0"]//div[@id="g0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList0"]//div[@id="g0"]/div')
                for i in content_one:
                    list_rsa = ['name']
                    list_ls = normalization(i.xpath('.//text()'))
                    list_rsa.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_regular_star_appearance, list_rsa)

            # (25)季后赛得分榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1pts0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1pts0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_score_total, list_zj)

            # (26)季后赛得分榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1pts1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1pts1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_score_average, list_zj)

            # (27)季后赛篮板榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1trb0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1trb0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_backboard_total, list_zj)

            # (28)季后赛篮板榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1trb1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1trb1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_backboard_average, list_zj)

            # (29)季后赛助攻榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1ast0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1ast0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_assists_total, list_zj)

            # (30)助攻季后赛榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1ast1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1ast1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_assists_average, list_zj)

            # (31)季后赛抢断榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1stl0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1stl0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_steal_total, list_zj)

            # (32)季后赛抢断榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1stl1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1stl1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_steal_average, list_zj)

            # (33)季后赛盖帽榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1blk0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1blk0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_cap_total, list_zj)

            # (34)季后赛盖帽榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1blk1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1blk1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_cap_average, list_zj)

            # (35)季后赛失误榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1tov0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1tov0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_mistake_total, list_zj)

            # (36)季后赛失误榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1tov1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1tov1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_mistake_average, list_zj)

            # (37)季后赛犯规榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1pf0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1pf0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_foul_total, list_zj)

            # (38)季后赛犯规榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1pf1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1pf1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_foul_average, list_zj)

            # (39)季后赛命中榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1fg0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1fg0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_hit_total, list_zj)

            # (40)季后赛命中榜命中率表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1fg1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1fg1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_hit_rate, list_zj)

            # (41)季后赛真实命中榜表
            if html.xpath('//div[@id="leaderList1"]//div[@id="ts0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="ts0"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_ture_hit, list_zj)

            # (42)季后赛三分榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1threep0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1threep0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_tp_total, list_zj)

            # (43)季后赛三分榜命中率表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1threep1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1threep1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_tp_hit_rate, list_zj)

            # (44)季后赛罚球榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1ft0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1ft0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_penalty_total, list_zj)

            # (45)季后赛罚球榜命中率表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1ft1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1ft1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_penalty_hit_rate, list_zj)

            # (46)季后赛打铁榜总计表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1kobe0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1kobe0"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_undefined_total, list_zj)

            # (47)季后赛打铁榜场均表
            if html.xpath('//div[@id="leaderList1"]//div[@id="1kobe1"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="1kobe1"]/div[@class="content"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_undefined_average, list_zj)

            # (48)季后赛出场次数榜表
            if html.xpath('//div[@id="leaderList1"]//div[@id="g0"]'):
                content_one = html.xpath(
                    '//div[@id="leaderList1"]//div[@id="g0"]/div')
                for i in content_one:
                    list_zj = [name]
                    list_ls = normalization(i.xpath('.//text()'))
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_playoff_star_appearance, list_zj)

        # 释放资源
        del one

    def get_team_superstar_peak_season(self):
        """
        获取队史巨星巅峰赛季数据（包含1个表）
        :return:
        """
        one = NBAdb()

        for url in self.url_list:
            # 解析HTML文档
            res = requests.get(url, headers=self.headers)
            res.encoding = 'utf-8'
            html = etree.HTML(res.text)

            # 通过URL在字典中获取球队名
            name = self.name_dic[url]

            if html.xpath('//div[@class="rowllList"]'):
                content_one = html.xpath('//div[@class="rowllList"]/div[@class="rowll"]')
                for i in content_one:
                    list_zj = [name]
                    list_ls = i.xpath('./div[@class="ll"]//text()')
                    list_zj.extend(list_ls)
                    one.insert_table(sql_insert_text.insert_team_superstar_peak_season_data, list_zj)

        # 释放资源
        del one


if __name__ == '__main__':
    print('ok')

